package cdu.hjx.project.sys.service.impl;

import cdu.hjx.project.pojo.Role;
import cdu.hjx.project.sys.mapper.RoleMapper;
import cdu.hjx.project.sys.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public int add(Role role) throws Exception {
        return roleMapper.add( role);
    }

    @Override
    public Role findByName(String role_name) throws Exception {
        return roleMapper.findByName( role_name);
    }

    @Override
    public List<Role> roles() throws Exception {
        return roleMapper.roles();
    }

    @Override
    public int insert(Role role) throws Exception {
        Role roleName = roleMapper.findByName(role.getRole_name());
        return null == roleName ? roleMapper.add(role) : -1;
    }

    @Override
    public int updateRole(Role role) throws Exception {
        return roleMapper.updateRole(role);
    }

    @Override
    public int deleteRole(Integer id) throws Exception {
        return roleMapper.deleteRole(id);
    }

    @Override
    public Role findRoleById(Integer id) {
        return roleMapper.findRoleById(id);
    }
}
